<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <c:import url="../../header.jsp"/>
    <link rel="stylesheet" type="text/css"
          href="https://tstatic.dgg.net/static/plugs/ztree/css/zTreeStyle/zTreeStyle.css"/>
    <link rel="stylesheet" type="text/css"
          href="${basePath}/static/css/production.css?v=${version}"/>
</head>
<body>
<div class="body-main">
    <div class="titleSearch">

        <div class="layui-inline">
            <div class="layui-inline">
                <label>所属事业部：</label>
                <%--<div class="layui-inline select2-inline">
                    <div class="layui-input-inline">
                        <input type="text" style="width: 180px" class="input-style" autocomplete="off"
                               id="selectTreeAddressId" name="selectTreeAddressId"
                               data-id="" data-orgid="" placeholder="请选择最下级的所属事业部"/>
                    </div>
                </div>--%>
                <div class="layui-input-inline">
                    <select class="select-style" id="selectTreeAddressId" name="selectTreeAddressId">
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label>业态：</label>
                <div class="layui-input-inline">
                    <div id="business_typeCode1">
                        <input type="hidden" name="typeCodeId" class="plug-in-msg"/>
                        <input type="hidden" name="typeCode" id="typeCode" class="plug-in-code"/>
                        <input type="text" readonly placeholder="请选择业态" class="chose-plugIn layui-input"
                               name="businessTypeName">
                        <div class="bus-picker">
                            <div class="bus-picker-tab">
                                <a href="javascript:void(0);" class="active">请选择业态</a>
                            </div>
                            <div class="bus-picker-content"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn layui-btn-mini layui-btn-normal"
                        onclick="reloadTable1()">搜索
                </button>
                <button type="button" class="layui-btn layui-btn-mini layui-btn-normal"
                        onclick="emptySearchValue(this)">
                    清空
                </button>
            </div>
        </div>
    </div>
    <div class="table-conter">
        <d:hasUrlAuth authCode="ZZSC_NODEMANAGER_CREATEFLOW">
        <a href="javascript:void(0)" class="layui-btn layui-btn-mini" onclick="OpenFlowCreateTabPage()">新建流程</a>
        </d:hasUrlAuth>
        <d:hasUrlAuth authCode="ZZSC_NODEMANAGER_EDITFLOWNODE">
        <a href="javascript:void(0)" class="layui-btn layui-btn-mini" onclick="EditFlowNode()">流程节点编辑</a>
        </d:hasUrlAuth>
        <d:hasUrlAuth authCode="ZZSC_NODEMANAGER_COPYFLOW">
        <a href="javascript:void(0)" class="layui-btn layui-btn-mini" onclick="CopyFlow()">复制流程</a>
        </d:hasUrlAuth>
    </div>
    <div class="table-body">
        <!--表格 start-->
        <table id="template" class="cell-border crm-table columnsHidden dataTable">
            <thead>
            <tr>
                <th><input type="checkbox" class="checkall"/></th>
                <th>序号</th>
                <th>编号</th>
                <th>适用事业部</th>
                <th>大业态</th>
                <th>小业态</th>
                <th>办理周期</th>
                <th>工作日/自然日</th>
                <th>审核级数</th>
                <th>最新操作时间</th>
                <th>最新操作人</th>
                <th>操作</th>
            </tr>
            </thead>
        </table>
        <!--表格 end-->
    </div>
</div>
<c:import url="../../footer.jsp"/>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
            $('#selectTreeAddressId').selectTree({
                check: false,   //默认为false，单选；设置为 true ，为多选
                search: true,
                parentIsCheck: false,
                url: cmsBaseUrl + "/api/cms/org/v1/find_all_parent_orgs.do?level=ORG_LEVEL_1&isFilterAB=1",//请求路 径
                form: true,
                idName: 'orgId',
                idKey: "id",//指定id
                pIdKey: "pId",//指定pId
                dataFilter: function (treeId, parentNode, responseData) {
                    return responseData.data;
                }

            });

        syb("#selectTreeAddressId");//初始化所属事业部
            //初始化下拉数据
        Plug.plug_ins("post", "${basePath}/zzsc/common/tree_book_list.do?code=BUS_YT_ZZ&&type=2&&level=2", "#business_typeCode1", '选择业态', '', true, 'BUS_YT_ZZ', '', '');
        //初始化dataTable列表
        var table = $('#template').dataTableExtend({
            "ajax": {"url": "${basePath}/zzsc/flownode/search.do", "type": "post"},
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData.deptIds = $('[name="selectTreeAddressId"]').val();
                aoData.businessCode = $('[name="typeCode"]').val();
            },
            "scrollX":"true",
            "fixedColumns":   {//锁定列，只有开启scrollX时才生效
			            "leftColumns": 2,//左侧锁定2列
			            "rightColumns": 1//右侧锁定1列
			        },
            "aoColumns": [
                {
                    "orderable": false,
                    "data": "id",
                    "render": function (data, type, full, meta) {
                        return '<input type="checkbox"  name="ids" class="checkchild"  value="' + data + '" />';
                    }
                }
                , {
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return meta.row + 1;

                    }
                }, {
                    "orderable": false,
                    "data": "flowNo",
                }, {
                    "orderable": false,
                    "data": "deptNames"
                }, {
                    "orderable": false,
                    "data": "bigformatCode"
                }, {
                    "orderable": false,
                    "data": "businessCode"
                }, {
                    "orderable": false,
                    "data": "managementCycle"
                }, {
                    "orderable": false,
                    "data": "isnaturalorworkday",
                    "render": function (d, type, r, meta) {
                        if (d == 1) {
                            return "工作日";
                        }
                        if (d == 2) {
                            return "自然日";
                        }
                    }
                }, {
                    "orderable": false,
                    "data": "examineGrade"
                },
                {
                    "orderable": true,
                    "data": "updateTime"
                }, {
                    "orderable": false,
                    "data": "updaterName"
                }, {
                    "orderable": false,
                    "data": "id",
                    "render": function (d, type, r, meta) {
                        var result = "";
                        <d:hasUrlAuth authCode="ZZSC_NODEMANAGER_EDITFLOW">
                        result += '<a href=\'javascript:void(0)\' class="layui-table-link"  onclick="OpenFlowEditTabPage(\'' + r.id + '\')" /><span style="color: #0066ff ">编辑</a>';
                        </d:hasUrlAuth>
                        return result;
                    }
                }]
        });

    });

    //清空筛选条件
    function emptySearchValue(obj) {
        if (undefined !== obj && null !== obj && '' !== obj) {
            $(obj).parents('div .titleSearch').find('input').filter(function () {
                return $(this).attr('type') !== 'hidden'
            }).each(function () {
                $(this).val('');
            });
            $(obj).parents('div .titleSearch').find('select').each(function () {
                $(this).val('');
            });
//            //区域
            $('#selectTreeAddressId').val('');
            $('#selectTreeAddressId').attr("data-id", '');
//            //业态
            $('[name="typeCodeId"]').val('');
            $('[name="typeCode"]').val('');
            var $s = $('.titleSearch');
            $s.find('input').val('');
            $s.find('select').val('');
            $s.find('select').val(null).trigger("change");
            $s.find('input').attr("data-id", '');
        } else {
            DGG.Layer.message('未找到要清空的元素！', {icon: '5'});
        }
    }

    /**
     * @describe: TODO 流程节点编辑
     * @author: 代杨
     * @creat_date: 2018/5/7  16:27
     **/
    function EditFlowNode() {
        var ids = getCheckedFlow();
        if (ids.length < 1) {
            DGG.Warning('请至少选中一个流程！');
            return;
        } else if (ids.length > 1) {
            DGG.Warning('只能选择一个流程！');
            return;
        }
        openEditFlowNodePage(ids);
    }

    /**
     * @describe: TODO 复制流程
     * @author: 代杨
     * @creat_date: 2018/5/7  16:28
     **/
    function CopyFlow() {
        var ids = getCheckedFlow();
        if (ids.length < 1) {
            DGG.Warning('请至少选中一个流程！');
            return;
        } else if (ids.length > 1) {
            DGG.Warning('只能选择一个流程！');
            return;
        }
        openCopyFlowPage(ids);
    }

    /**
     * @describe: TODO 获取流程选择
     * @author: 代杨
     * @creat_date: 2018/5/7  16:28
     **/
    function getCheckedFlow() {
        var datas = $('#template').dataTableExtend('getCheck');
        var ids = [];
        for (var i = 0; i < datas.length; i++) {
            ids.push(datas[i].id);
        }
        return ids;
    }

    /**
     * 打开新建流程页面
     */
    function OpenFlowCreateTabPage() {
        $.post(sysInfo.basePath + "/zzsc/flownode/flowcreate_tabpage.html", function (data) {
            dgg.Open({
                title: '新建流程',
                content: data,
                area: '30%',
                btn: ["确定", "取消"],
                yes: function () {
                    flowCreate();
                }, btn2: function () {

                }
            });
        }, 'html');

    }

    /**
     * 打开编辑流程页面
     */
    function OpenFlowEditTabPage(flowId) {
        $.post(sysInfo.basePath + "/zzsc/flownode/flowedit_tabpage.html", {flowId: flowId}, function (data) {
            dgg.Open({
                title: '编辑流程',
                content: data,
                area: '30%',
                btn: ["确定", "取消"],
                yes: function () {
                    flowEdit()
                }
            });
        }, 'html');

    }

    /**
     * 打开编辑流程节点页面
     */
    function openEditFlowNodePage(flowId) {
        var url = sysInfo.basePath + "/zzsc/flownode/open_edit_flownode_page.html?flowId=" + flowId;
        //新增tabs
        window.parent.updateTab("编辑流程节点", url);
    }

    /**
     * 打开复制流程页面
     */
    function openCopyFlowPage(flowId) {

        $.post(sysInfo.basePath + "/zzsc/flownode/flowcopy_tabpage.html", {flowId: flowId[0]}, function (data) {
            dgg.Open({
                title: '复制流程',
                content: data,
                area: '30%',
                btn: ["确定", "取消"],
                yes: function () {
                    flowCopy();
                }, btn2: function () {

                }
            });
        }, 'html');
    }

    function reloadTable1() {
        $('#template').dataTableExtend("reload");
    }

    var orderDetail = function (id) {
        window.location.href = "${basePath}/orf/order/queryOrderdetails?orderId=" + id

    }
</script>
</body>
</html>